// const uuid = require('uuid/v4')
// const md5 = require('md5')
// const xml2js = require('xml2js')
// const Parser = new xml2js.Parser()

// const request = require('request')
const prepay = require('../tools/payTools')

// const prepay_url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'

module.exports = async (ctx) => {
    const {
        openId,
        orderId,
        total_fee
    } = ctx.request.body;
    const requestIP = ctx.request.ip.replace(/::ffff:/g, '')
    let res = await prepay(openId, orderId, requestIP, total_fee);
    console.log(res,ctx.request.ip);
    if (res.paySign) {
        ctx.body = {
            code: '001',
            data: res
        }
    } else {
        ctx.body = {
            code: '002'
        }
    }
}